<?php self::header (); ?>
<?php
	if (isset ($_POST['suggestion']) && !isset ($_POST['suggest_new'])) {
		$suggestion = $_POST['suggestion'];
	} else {
		$nouns = explode ("\n", file_get_contents (PATH.'/private/nouns.txt'));
		$verbs = explode ("\n", file_get_contents (PATH.'/private/verbs.txt'));
		$adjectives = explode ("\n", file_get_contents (PATH.'/private/adjectives.txt'));
	
		$suggestion = 
			ucfirst ($nouns[array_rand ($nouns)]).
			ucfirst ($verbs[array_rand ($verbs)]).
			ucfirst ($adjectives[array_rand ($adjectives)]).
			ucfirst ($nouns[array_rand ($nouns)]).
			rand (0,100);
	}
?>
<div class="container">
    <div class="hero-unit">
      <div>
        <h1>
          60 second sign-up.
        </h1>
        <p style="margin-top: 15px; margin-bottom: 20px; margin-left: 5px;">
          You're moments away from enjoying PassKey freedom - possibly with your friends and colleagues.<br />
          All PassKey needs is your username, password and name.  Oh and an email address to verify you're you!<br />
          The details you enter here will be used for others to share their data with you, so make sure it's spelt right.
        </p>
      </div>
      <form action="<?php print URL; ?>/account/create" method="post" class="form-horizontal">
        <div class="control-group">
			<label class="control-label" for="inputEmail">Username & Password:</label>
			<div class="controls">
				<input type="hidden" name="suggestion" value="<?php print $suggestion; ?>" />
				<input name="username" type="text" placeholder="jblogs" value="<?php self::eprint ($data['username']); ?>" <?php if (isset ($data['errors']['bad_username'])): ?>style="background-color: #ffe0e0"<?php endif; ?> />
				<?php if (isset ($_POST['use_suggestion']) && !isset ($_POST['choose_own'])): ?>
				<small><code><?php print $suggestion; ?></code></small>
				<input type="hidden" name="password" value="<?php self::eprint ($suggestion); ?>" />
				<input type="submit" name="suggest_new" value="Suggest Another" class="btn btn-mini" />
				<input type="hidden" name="use_suggestion" value="true" />
				<input type="submit" name="choose_own" value="Choose My Own" class="btn btn-success btn-mini" />
				<?php else: ?>
				<input name="password" type="password" value="<?php self::eprint ($data['password']); ?>" placeholder="<?php print $suggestion; ?>" <?php if (isset ($data['errors']['bad_password'])): ?>style="background-color: #ffe0e0"<?php endif; ?> />
				<input type="submit" name="use_suggestion" value="Use a Suggestion" class="btn btn-success btn-mini" />				
				<?php endif; ?>
			</div>
			<label class="control-label" for="inputEmail">First & Last name:</label>
			<div class="controls">
				<input name="firstname" type="text" value="<?php self::eprint ($data['firstname']); ?>" placeholder="Joe" <?php if (isset ($data['errors']['bad_firstname'])): ?>style="background-color: #ffe0e0"<?php endif; ?> />
				<input name="lastname" type="text" value="<?php self::eprint ($data['lastname']); ?>" placeholder="Blogs" <?php if (isset ($data['errors']['bad_lastname'])): ?>style="background-color: #ffe0e0"<?php endif; ?> />
			</div>
			<label class="control-label" for="inputEmail">Email address:</label>
			<div class="controls">
				<input name="email" type="text" value="<?php self::eprint ($data['email']); ?>" placeholder="joe.blogs@example.com" <?php if (isset ($data['errors']['bad_email'])): ?>style="background-color: #ffe0e0"<?php endif; ?> />
				&nbsp;<small><i class="icon-arrow-left"></i> A verification email will be sent to this address which you'll need to open the account.</small>
			</div>
		</div>
        <div class="control-group">
			<div class="controls">
		        <input type="submit" name="create" class="btn btn-primary btn-large" style="position: relative; top: -5px;" value="Create Account" />
		        <?php if (sizeof ($data['errors']) > 0 && !isset ($data['errors']['database_error']) && !isset ($data['errors']['registered_username']) && !isset ($data['errors']['registered_email'])): ?>
		        <span style="margin-left: 20px;" class="text-error">Please double-check and amend the highlighted fields above.</span>
		        <?php elseif (isset ($data['errors']['database_error'])): ?>
		        <span style="margin-left: 20px;" class="text-error"><?php self::eprint ($data['errors']['database_error']); ?></span>
		        <?php elseif (isset ($data['errors']['registered_email'])): ?>
		        <span style="margin-left: 20px;" class="text-error">Your email address is already registered.</span>
		        <?php elseif (isset ($data['errors']['registered_username'])): ?>
		        <span style="margin-left: 20px;" class="text-error">That username is already registered.</span>
		        <?php endif; ?>
		    </div>
        </div>
      </form>
    </div>
</div>
<?php self::footer (); ?>